import java.io.File;
import java.io.UnsupportedEncodingException;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swf.seed.base.SystemContants;
import com.swf.seed.security.cert.SecurityCertSigner;
import com.swf.seed.util.PropUtil;


public class SybSign {
	private static final Logger logger = LoggerFactory.getLogger(SybSign.class);
	/**
	 * @param args
	 * @throws Exception 
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws UnsupportedEncodingException, Exception {
		String charset = PropUtil.getPropValue("charset");
		System.out.println(new File(SystemContants.PROJECT_PATH,"signData.properties").exists());
		PropUtil.changePropFile(new File(SystemContants.PROJECT_PATH,"signData.properties").getAbsolutePath());
		System.out.println(PropUtil.propFile);
		String signFieldStr = PropUtil.getPropValue("signFieldStr");
		if (signFieldStr==null){
			logger.error("config.properties中找不到签名字段属性signFieldStr");
			return;
		}
		String[] signFields = signFieldStr.split("\\|"); 
		StringBuilder sb = new StringBuilder();
		for (String signField:signFields){
			String value = PropUtil.getPropValueByCharst(signField, charset);
			if (StringUtils.isBlank(value)){
				logger.error(signField+"字段不存在或者为空");
				System.exit(0);
			}
			sb.append("|").append(value);
		}
		String signOrgin = sb.toString().substring(1);
		System.out.println("签名原文："+signOrgin);
		SecurityCertSigner.signData(signOrgin, charset);

	}

}
